package com.chris.libs.example.common.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;

import com.chris.libs.example.R;
import com.chris.libs.example.model.FunItem;

/**
 * @author Chris chan
 * Create on： 2025/2/1 20:53
 * Use for:
 * Explain:
 */
public class FunItemUtil {
    public static void addButton(Context context, ViewGroup container, FunItem funItem) {
        addButton(context, container, funItem.getTitle(), funItem.getTargetActivityClass());
    }

    public static void addButton(Context context, ViewGroup container, String title, Class<? extends Activity> targetActivityClass) {
        // 创建按钮
        Button button = new Button(context);
        button.setText(title);
        button.setBackgroundResource(R.drawable.bg_btn_normal);
        button.setTextColor(Color.WHITE);

        container.addView(button);

        // 按钮间隔
        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) button.getLayoutParams();
        layoutParams.setMargins(0, 5, 0, 5);
        button.setLayoutParams(layoutParams);

        // 点击事件
        button.setOnClickListener(v -> context.startActivity(new Intent(context, targetActivityClass)));
    }
}
